<?php

/* 
 * EachGo电商网站 新媒体
 * www.eachgo.cn
 */
namespace Home\Model;
use Think\Model;
class ShippingAddressModel extends Model{
    public function addAddress($data){
        return $this->add($data);
    }
    /*删除分享*/
    public function deleteAddress($id){
        $sql="UPDATE EachGo.`t_shipping_address` SET isDelete = TRUE WHERE ID=".$id;
        return $this->execute($sql);
    }
    /*查询所有分享*/
    public function queryAllAddress($phoneNumber){
        return $this->where("user_phoneNumber=".$phoneNumber." AND isDelete=false ")->order('isDefault DESC')->select();
    }
    public function queryAddressByUserId($phoneNumber){
        return $this->where("user_phoneNumber=".$phoneNumber)->order('isDefault DESC')->select();
    }
    public function updateAddress($data){
        return $this->where("ID=".$data['addressId'])->save($data);
    }
    public function setDefault($userPhone,$addressId){
        $setAll="UPDATE EachGo.`t_shipping_address` SET isDefault=FALSE WHERE user_phoneNumber=".$userPhone;
        $resultAll=$this->execute($setAll);
        $setDefault="UPDATE EachGo.`t_shipping_address` SET isDefault=TRUE WHERE ID=".$addressId;
        $resultDefualt=$this->execute($setDefault);
    }
}
